<?php
/**
 * Created by PhpStorm.
 * User: Sun Jian
 * Date: 2018/1/3
 * Time: 13:43
 */

namespace frontend\controllers;

use yii\web\Controller;
use Yii;

class BaseController extends Controller
{
    function init()
    {

        $language=Yii::$app->request->cookies->getValue("language");
        if(!$language){
            $defaultLanguage=$_SERVER["HTTP_ACCEPT_LANGUAGE"];
            if(stripos(substr($defaultLanguage,0,5),'zh')){
                $language="zh-CN";
            }else{
                $language="en-US";
            }
        }
        Yii::$app->language = $language;
    }

}